package cn.iocoder.yudao.module.train.dal.mysql.studentcoursescore;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.train.dal.dataobject.connectDTO.StudentCourseScoreStudentDTO;
import cn.iocoder.yudao.module.train.dal.dataobject.student.StudentDO;
import cn.iocoder.yudao.module.train.dal.dataobject.studentcoursescore.StudentCourseScoreDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.train.controller.admin.studentcoursescore.vo.*;

/**
 * 学生课程成绩 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface StudentCourseScoreMapper extends BaseMapperX<StudentCourseScoreDO> {

//    default PageResult<StudentCourseScoreDO> selectPage(StudentCourseScorePageReqVO reqVO) {
//        return selectPage(reqVO, new LambdaQueryWrapperX<StudentCourseScoreDO>()
//                .eqIfPresent(StudentCourseScoreDO::getTeachingId, reqVO.getTeachingId())
//                .eqIfPresent(StudentCourseScoreDO::getStudentId, reqVO.getStudentId())
//                .eqIfPresent(StudentCourseScoreDO::getScore, reqVO.getScore())
//                .eqIfPresent(StudentCourseScoreDO::getLevel, reqVO.getLevel())
//                .betweenIfPresent(StudentCourseScoreDO::getCreateTime, reqVO.getCreateTime())
//                .orderByDesc(StudentCourseScoreDO::getId));
//    }

    default PageResult<StudentCourseScoreStudentDTO> selectPage(StudentCourseScorePageReqVO reqVO) {
        Page<StudentCourseScoreStudentDTO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        MPJLambdaWrapper<StudentCourseScoreDO> wrapper = new MPJLambdaWrapper<StudentCourseScoreDO>()
                .selectAll(StudentCourseScoreDO.class)
                .select(StudentDO::getStudentName)
                .select(StudentDO::getStudentPhoneNumber)
                .leftJoin(StudentDO.class, on -> on
                        .eq(StudentDO::getId, StudentCourseScoreDO::getStudentId))
                .eqIfExists(StudentCourseScoreDO::getClassesId, reqVO.getClassesId())
                .eqIfExists(StudentCourseScoreDO::getStudentId, reqVO.getStudentId())
                .likeIfExists(StudentCourseScoreDO::getLevel, reqVO.getLevel())
                .likeIfExists(StudentDO::getStudentName, reqVO.getStudentName())
                .orderByDesc(StudentCourseScoreDO::getId);
        IPage<StudentCourseScoreStudentDTO> resultPage = selectJoinPage(page, StudentCourseScoreStudentDTO.class, wrapper);
        return new PageResult<>(resultPage.getRecords(), resultPage.getTotal());
    }

    default StudentCourseScoreStudentDTO selectById(Integer studentId) {
        return selectJoinOne(StudentCourseScoreStudentDTO.class,
                new MPJLambdaWrapper<StudentCourseScoreDO>()
                        .selectAll(StudentCourseScoreDO.class)
                        .select(StudentDO::getStudentName)
                        .leftJoin(StudentDO.class, StudentDO::getId, StudentCourseScoreDO::getStudentId)
                        .eq(StudentCourseScoreDO::getId, studentId)
        );
    }

}
